package com.zlc.platform.controller;


import com.zlc.common.annotation.LogSaveAnnotation;
import com.zlc.common.common.constant.PlatConstant;
import com.zlc.common.core.dept.model.vo.MayanPlatDeptVo;
import com.zlc.common.core.position.model.vo.MayanPlatDeptPositionVo;
import com.zlc.common.core.position.model.vo.MayanPlatPositionUserVo;
import com.zlc.common.core.position.model.vo.MayanPlatPositionVo;
import com.zlc.common.core.user.model.vo.MayanPlatUserVo;
import com.zlc.common.model.dept.DeptVo;
import com.zlc.platform.service.DeptService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Api(tags = "部门相关")
@RestController
@Slf4j
@RequestMapping("/api/dept")
public class DeptController {

    @Autowired
    private DeptService deptService;

    /**
     * 新增部门
     */
    @ApiOperation(value = "新增部门")
    @PostMapping(value = "/addDept")
    @LogSaveAnnotation(module = PlatConstant.UC_APP_MODULE, recordRequestParam = true, title = "新增部门", catalog = "权限管理/组织管理")
    public void addDept(@RequestBody MayanPlatDeptVo deptVo) {
        deptService.addDept(deptVo);
    }


    /**
     * 修改部门信息
     */
    @ApiOperation(value = "修改部门信息")
    @PostMapping(value = "/updateDept")
    @LogSaveAnnotation(module = PlatConstant.UC_APP_MODULE, recordRequestParam = true, title = "修改部门信息", catalog = "权限管理/组织管理")
    public void updateDept(@RequestBody MayanPlatDeptVo deptVo) {
        deptService.updateDept(deptVo);
    }


    /**
     * 查询单个部门信息
     */
    @ApiOperation(value = "查询单个部门信息")
    @GetMapping(value = "/queryOne")
    public MayanPlatDeptVo queryOne(@RequestParam(value = "deptId") String deptId) {
        return deptService.queryOne(deptId);
    }


    /**
     * 查询所有组织树
     */
    @ApiOperation(value = "查询所有组织树")
    @GetMapping(value = "/queryDeptVo")
    public DeptVo queryDeptVo() {
        return deptService.queryDeptVo();
    }


    /**
     * 添加部门岗位
     */
    @ApiOperation(value = "添加部门岗位")
    @PostMapping(value = "/addDeptPosition")
    @LogSaveAnnotation(module = PlatConstant.UC_APP_MODULE, recordRequestParam = true, title = "添加部门岗位", catalog = "权限管理/组织管理")
    public void addDeptPosition(@RequestBody MayanPlatDeptPositionVo deptPositionVo) {
        deptService.addDeptPosition(deptPositionVo);
    }


    /**
     * 移除部门关联岗位
     */
    @ApiOperation(value = "移除部门关联岗位")
    @PostMapping(value = "/removeDeptPosition")
    @LogSaveAnnotation(module = PlatConstant.UC_APP_MODULE, recordRequestParam = true, title = "移除部门关联岗位", catalog = "权限管理/组织管理")
    public void removeDeptPosition(@RequestBody Map<String, String> map) {
        deptService.removeDeptPosition(map.get("relateId"));
    }


    /**
     * 通过部门编码查询关联的部门岗位
     */
    @ApiOperation(value = "通过部门编码查询关联的部门岗位")
    @GetMapping(value = "/queryDeptPositions")
    public List<MayanPlatPositionVo> queryDeptPositions(@RequestParam(value = "deptCode") String deptCode) {
        return deptService.queryDeptPositions(deptCode);
    }


    /**
     * 添加岗位员工
     */
    @ApiOperation(value = "添加岗位员工")
    @PostMapping(value = "/addDeptPositionUser")
    @LogSaveAnnotation(module = PlatConstant.UC_APP_MODULE, recordRequestParam = true, title = "添加岗位员工", catalog = "权限管理/组织管理")
    public void addDeptPositionUser(@RequestBody MayanPlatPositionUserVo positionUserVo) {
        deptService.addDeptPositionUser(positionUserVo);
    }


    /**
     * 移除岗位关联员工
     */
    @ApiOperation(value = "移除岗位关联员工")
    @PostMapping(value = "/removeDeptPositionUser")
    @LogSaveAnnotation(module = PlatConstant.UC_APP_MODULE, recordRequestParam = true, title = "移除岗位关联员工", catalog = "权限管理/组织管理")
    public void removeDeptPositionUser(@RequestBody Map<String, String> map) {
        deptService.removeDeptPositionUser(map.get("relateId"));
    }


    /**
     * 查询部门岗位下员工
     */
    @ApiOperation(value = "查询部门岗位下员工")
    @GetMapping(value = "/queryPositionUsers")
    public List<MayanPlatUserVo> queryPositionUsers(@RequestParam(value = "deptCode") String deptCode,
                                                    @RequestParam(value = "positionCode") String positionCode) {
        return deptService.queryPositionUsers(deptCode, positionCode);
    }

    /**
     * 查询部门下员工
     */
    @ApiOperation(value = "查询部门下员工")
    @GetMapping(value = "/queryDeptUsers")
    public List<MayanPlatUserVo> queryDeptUsers(@RequestParam(value = "deptCode") String deptCode) {
        return deptService.queryDeptUsers(deptCode);
    }
}
